// Vector

Assault.Vector = {}

// Add

function Assault.Vector.__add(A, B)
	if (type(A) != "table") then A = {X = A, Y = A} end
	if (type(B) != "table") then B = {X = B, Y = B} end
	
	// Return new
	
	return Assault.Vector:New(A.X + B.X, A.Y + B.Y)
end

// Unm

function Assault.Vector:__unm(A)
	return Assault.Vector:New(-A.X, -A.Y)
end

// Sub

function Assault.Vector.__sub(A, B)
	if (type(A) != "table") then A = {X = A, Y = A} end
	if (type(B) != "table") then B = {X = B, Y = B} end
	
	// Return new
	
	return Assault.Vector:New(A.X - B.X, A.Y - B.Y)
end

// Mul

function Assault.Vector.__mul(A, B)
	if (type(A) != "table") then A = {X = A, Y = A} end
	if (type(B) != "table") then B = {X = B, Y = B} end
	
	// Return new
	
	return Assault.Vector:New(A.X * B.X, A.Y * B.Y)
end


// New

function Assault.Vector:New(X, Y)
	local Table = {}
	
	// Meta table
	
	setmetatable(Table, self)
	
	// Index
	
	self.__index = self
	
	// Vector
	
	Table.X = X
	Table.Y = Y
	
	// Return table
	
	return Table
end

// Get vector normal

function Assault.Vector:GetVectorNormal()
	local Len = math.sqrt((self.X ^ 2) + (self.Y ^ 2))
	
	// X and Y
	
	local X = self.X / Len
	local Y = self.Y / Len
	
	// Return vector
	
	return self:New(X, Y)
end

// Get vector dot product

function Assault.Vector:GetVectorDotProduct(Vector)
	local Product = (self.X * Vector.X) + (self.Vector.Y * Vector.Y)
	
	// Return product
	
	return Product
end

// Get vector distance

function Assault.Vector:GetVectorDistance(Vector)
	local X = (Vector.X - self.X) ^ 2
	local Y = (Vector.Y - self.Y) ^ 2
	
	// Result
	
	local Result = math.sqrt(X + Y)
	
	// Return result
	
	return Result
end

// Vector inside vector

function Assault.Vector:VectorInsideVector(AW, AH, Vector, BW, BH)
	if (self.X + AW > BX) and (self.X + AW < Vector.X + BW) and (self.Y + AH > Vector.Y) and (self.Y + AH < Vector.Y + BH) then
		return true
	elseif (self.X - AW > BX) and (self.X - AW < Vector.X + BW) and (self.Y - AH > Vector.Y) and (self.Y - AH < Vector.Y + BH) then
		return true
	end
	
	// Return false
	
	return false
end